package com.ego.item.controller;


import com.ego.item.pojo.ItemCategoryNav;
import com.ego.pojo.TbItemDetail;
import com.ego.item.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
public class ItemController {


    @Autowired
    private ItemCatService itemCatService;

    //查询首页所有商品类目
    @GetMapping("/rest/itemcat/all")
    @ResponseBody
    @CrossOrigin //支持跨域请求
    public ItemCategoryNav showItemCat(){
        return itemCatService.selectAllCat();
    }



    //查询商品详情
    @GetMapping("/item/{id}.html")
    public String itemDetail(@PathVariable  Long id, Model model){
        System.out.println("id = " + id);

        TbItemDetail tbItemDetail = itemCatService.selectById(id);

        model.addAttribute("item",tbItemDetail);

        return "item";
    }

    //查询商品描述
    @GetMapping("item/desc/{id}.html")
    @ResponseBody
    public String itemDesc(@PathVariable Long id){

        String itemDesc = itemCatService.selectItemDescByItemId(id);

        return itemDesc;
    }
    //查询商品规格参数
    @GetMapping("/item/param/{id}.html")
    @ResponseBody
    public String itemParam(@PathVariable Long id){

        String itemParm = itemCatService.selectItemParamByItemId(id);

        return itemParm;
    }


}
